package orest.front.achieve;

 import java.io.PrintStream;
 import java.util.ArrayList;
 import java.util.Iterator;

import net.ssta.core.db.Record;
import net.ssta.core.db.RecordSet;
 import orest.common.dao.KjcgDao;
 import orest.common.response.Response;
 import orest.common.valueobject.KjcgVal;
import orest.common.util.GetOption;

 public class KjcgAction
{
 public String findKjcgByContion(String sql, int pageNo, int pageRecords, long ttl)
{
              Response rp = new Response();
              KjcgDao obj = new KjcgDao();
              StringBuffer result = new StringBuffer();
              boolean opReturn = true;
              String temp = "";
              long total = 0L;
              RecordSet rcdSet = new RecordSet();
              try
              {
                if ((pageNo <= 1) || ((pageNo > 1) && (ttl == 0L)))
                   total = obj.countKjcgByCondition(sql, rp);
                else
                   total = ttl;
                opReturn = obj.findKjcgByConditon(rp, sql, pageNo, pageRecords, (int)total);
                if (!opReturn)
                   return null;
               }
              catch (Exception e)
               {
                 e.printStackTrace();
               }
               result.append("<total>");
              result.append(total);
              result.append("</total>");
              ArrayList al = rp.getValObjs();
              Iterator iterator = al.iterator();
              try
               { 
                  while (iterator.hasNext())
                {
                  Record record = new Record();
                  KjcgVal objElem = (KjcgVal)iterator.next();
                  result.append("<record>");
                  result.append("<KjcgID>");
                   result.append(objElem.getKjcgID());
                   record.addData("KJCGID",objElem.getKjcgID());
                  result.append("</KjcgID>");
                  result.append("<Kjcg_Item_3><![CDATA[");
                  result.append(objElem.getKjcg_Item_3());
                  
                  record.addData("KJCG_ITEM_3",objElem.getKjcg_Item_3());
                  
                  result.append("]]></Kjcg_Item_3>");
                  result.append("<UnitID>");
                  result.append(objElem.getUnitID());
                  record.addData("UNITID",objElem.getUnitID());
                  
                  result.append("</UnitID>");
                  result.append("<Kjcg_Item_9><![CDATA[");
                  result.append(objElem.getKjcg_Item_9());
                  record.addData("KJCG_ITEM_9",objElem.getKjcg_Item_9());
                  
                  result.append("]]></Kjcg_Item_9>");
                  result.append("<Kjcg_Item_13_1s><![CDATA[");
                  result.append(objElem.getKjcg_Item_13_1s());
                  record.addData("KJCG_ITEM_13_1S",objElem.getKjcg_Item_13_1s());
                  
                  result.append("]]></Kjcg_Item_13_1s>");
                  result.append("</record>");
                  objElem = null;
                  
                  record.addData("total",total);
                  rcdSet.add(record);
                }
               }
              catch (Exception e)
              {
                System.out.println("when encoding the string, exception occured.");
                System.out.println("The class is KjcgAction and the function is findKjcgByConditon");
              }
                  al = null;
               obj = null;
               rp = null;
               //return result.toString();
               return rcdSet.getJsonString();
}
              
 public String findTopKjcgByContion(String sql, String num,String sorttype)
 {
              Response rp = new Response();
              KjcgDao obj = new KjcgDao();
              StringBuffer result = new StringBuffer();
              boolean opReturn = true;
              String temp = "";
              long total = 0L;
              try
              {
                opReturn = obj.findTopKjcgByCondition(rp, num, sql,sorttype);
                if (!opReturn)
                  return null;
              }
              catch (Exception e)
              {
                e.printStackTrace();
              }
              
              ArrayList al = rp.getValObjs();
              Iterator iterator = al.iterator();
              try
              {
                while (iterator.hasNext())
                {
                  KjcgVal objElem = (KjcgVal)iterator.next();
                  result.append("<record>");
                  result.append("<KjcgID>");
                  result.append(objElem.getKjcgID());
                  result.append("</KjcgID>");
                  result.append("<Kjcg_Item_3><![CDATA[");
                  result.append(objElem.getKjcg_Item_3());
                  result.append("]]></Kjcg_Item_3>");
                  result.append("</record>");
                  objElem = null;
                }
              }
              catch (Exception e)
              {
                System.out.println("when encoding the string, exception occured.");
                System.out.println("The class is KjcgAction and the function is findTopKjcgByConditon");
              }
              
              al = null;
              obj = null;
              rp = null;
              return result.toString();
              }
 
 public String findKjcgByPrk(String id)
{
              Response rp = new Response();
              KjcgDao obj = new KjcgDao();
              StringBuffer result = new StringBuffer();
              boolean opReturn = true;
              GetOption gpt = new GetOption();
              try
              {
                
                opReturn = obj.findKjcgByPrk(rp,id);
                
                if (!opReturn)
                   return null;
               }
              catch (Exception e)
               {
                 e.printStackTrace();
               }
               
              ArrayList al = rp.getValObjs();
              Iterator iterator = al.iterator();
              Record record = new Record();
              try
               {              
                  while (iterator.hasNext())
                {
                  KjcgVal objElem = (KjcgVal)iterator.next();
                  result.append("<record>");
                  
                  result.append("<KjcgID>");
                   result.append(objElem.getKjcgID());
                  record.addData("kjcgid", objElem.getKjcgID());
                  result.append("</KjcgID>");
                   
                   
                  result.append("<Kjcg_Item_3><![CDATA[");
                  result.append(objElem.getKjcg_Item_3());
                  record.addData("kjcg_item_3", objElem.getKjcg_Item_3());
                  result.append("]]></Kjcg_Item_3>");
                  
                  result.append("<UnitID>");
                  result.append(objElem.getUnitID());
                  record.addData("unitid", objElem.getUnitID());
                  result.append("</UnitID>");
                  
                  result.append("<Kjcg_Item_9><![CDATA[");
                  result.append(objElem.getKjcg_Item_9());
                  record.addData("kjcg_item_9", objElem.getKjcg_Item_9());
                  result.append("]]></Kjcg_Item_9>");
                  
                  result.append("<Kjcg_Item_13_1><![CDATA[");
                  result.append(objElem.getKjcg_Item_13_1());
                  record.addData("kjcg_item_13_1", objElem.getKjcg_Item_13_1());
                  result.append("]]></Kjcg_Item_13_1>");
                  
                  result.append("<Kjcg_Item_13><![CDATA[");
                  result.append(objElem.getKjcg_Item_13());
                  record.addData("kjcg_item_13", objElem.getKjcg_Item_13());
                  result.append("]]></Kjcg_Item_13>");
                  
                  result.append("<Kjcg_Item_120>");
                  result.append(objElem.getKjcg_Item_120());
                  record.addData("kjcg_item_120", objElem.getKjcg_Item_120());
                  result.append("</Kjcg_Item_120>");
                  
                  result.append("<Kjcg_Item_cglb>");
                  result.append(gpt.getXxmcFromXxdm("item_cglb",objElem.getKjcg_Item_cglb()));
                  record.addData("kjcg_item_cglb", gpt.getXxmcFromXxdm("item_cglb",objElem.getKjcg_Item_cglb()));
                  result.append("</Kjcg_Item_cglb>");
                  
                  result.append("<Kjcg_Item_121>");
                  result.append(objElem.getKjcg_Item_121());
                  record.addData("kjcg_item_121", objElem.getKjcg_Item_121());
                  result.append("</Kjcg_Item_121>");
                  
                  result.append("<Kjcg_Item_8>");
                  result.append(objElem.getKjcg_Item_8());
                  record.addData("kjcg_item_8", objElem.getKjcg_Item_8());
                  result.append("</Kjcg_Item_8>");
                  
                   result.append("<Kjcg_Item_210>");
                  result.append(gpt.getXxmcFromXxdm("item_210",objElem.getKjcg_Item_210()));
                  record.addData("kjcg_item_210", gpt.getXxmcFromXxdm("item_210",objElem.getKjcg_Item_210()));
                  result.append("</Kjcg_Item_210>");
                  
                   result.append("<Kjcg_Item_123>");
                  result.append(gpt.getXxmcFromXxdm("item_123",objElem.getKjcg_Item_123()));
                  record.addData("kjcg_item_123", gpt.getXxmcFromXxdm("item_123",objElem.getKjcg_Item_123()));
                  result.append("</Kjcg_Item_123>");
                  
                   result.append("<Kjcg_Item_16>");
                  result.append(gpt.getXxmcFromXxdm("item_16",objElem.getKjcg_Item_16()));
                  record.addData("kjcg_item_16", gpt.getXxmcFromXxdm("item_16",objElem.getKjcg_Item_16()));
                  result.append("</Kjcg_Item_16>");
                  
                  result.append("<Kjcg_Item_125_1>");
                  result.append(gpt.getXxmcFromXxdm("item_125_1",objElem.getKjcg_Item_125_1()));
                  record.addData("kjcg_item_125_1", gpt.getXxmcFromXxdm("item_125_1",objElem.getKjcg_Item_125_1()));
                  result.append("</Kjcg_Item_125_1>");
                  
                  result.append("<Kjcg_Item_2>");
                  result.append(gpt.getXxmcFromXxdm("item_2",objElem.getKjcg_Item_2()));
                  record.addData("kjcg_item_2", gpt.getXxmcFromXxdm("item_2",objElem.getKjcg_Item_2()));
                  result.append("</Kjcg_Item_2>");
                  
                  result.append("<Kjcg_Item_201>");
                  result.append(gpt.getXxmcFromXxdm("item_201",objElem.getKjcg_Item_201()));
                  record.addData("kjcg_item_201", gpt.getXxmcFromXxdm("item_201",objElem.getKjcg_Item_201()));
                  result.append("</Kjcg_Item_201>");
                  
                  result.append("<Kjcg_Item_41>");
                  result.append(objElem.getKjcg_Item_41());
                  record.addData("kjcg_item_41", objElem.getKjcg_Item_41());
                  result.append("</Kjcg_Item_41>");
                  
                  result.append("<Kjcg_Item_41_2>");
                  result.append(objElem.getKjcg_Item_41_2());
                  record.addData("kjcg_item_41_2", objElem.getKjcg_Item_41_2());
                  result.append("</Kjcg_Item_41_2>");
                  
                  result.append("<AchieveType>");
                  result.append(objElem.getKjcg_Item_125_1());
                  record.addData("achievetype", objElem.getKjcg_Item_125_1());
                  result.append("</AchieveType>");
                  
                  result.append("</record>");
                  objElem = null;
                }
               }
              catch (Exception e)
              {
                System.out.println("when encoding the string, exception occured.");
                System.out.println("The class is KjcgAction and the function is findKjcgByPrk");
              }
                  al = null;
               obj = null;
               rp = null;
                 //return result.toString();
               return record.getJsonString();
}
 
 public String findUnitIDByKjcgID(String id)
{
              Response rp = new Response();
              KjcgDao obj = new KjcgDao();
              String unitid="";
              boolean opReturn = true;
              
              try
              {      
                opReturn = obj.findUnitIDByKjcgID(rp,id);
                if (!opReturn)
                   return null;
               }
              catch (Exception e)
               {
                 e.printStackTrace();
               }
               
              ArrayList al = rp.getValObjs();
              Iterator iterator = al.iterator();
              try
              {              
                  while (iterator.hasNext())
                 {  KjcgVal objElem = (KjcgVal)iterator.next();
                    unitid = objElem.getUnitID();
                  }
               }
              catch (Exception e)
              {
                System.out.println("when encoding the string, exception occured.");
                System.out.println("The class is KjcgAction and the function is findKjcgByPrk");
              }
               al = null;
               obj = null;
               rp = null;
               return unitid;
               }
 
 }